









<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>
		jaks-system</title>
    <link rel="stylesheet" href="./css/maven-theme.css" type="text/css" />
    <link rel="stylesheet" href="./css/maven-base.css" type="text/css"/>
    <link rel="stylesheet" href="./css/prettify.css" type="text/css"/>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
    <script type="text/javascript" src="./js/prettify.js"></script>
    <script type="text/javascript" src="./js/niftycube.js"></script>
    <script type="text/javascript">
        window.onload=function() {
            Nifty("div\#wrapper", "big");
            Nifty("div#breadcrumbs", "small");
            Nifty("div\#navcolumn", "small");
            Nifty("div.source", "medium");
            prettyPrint();
        }
    </script>
          <meta name="author" content="Jason Smith" />
        <meta name="Date-Revision-yyyymmdd" content="20120515" />
      </head>
  <body>
    <div id="wrapper">
        <div id="banner">
                        <div id="bannerLeft">
    
            jaks-system
    
            </div>
                            <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="breadcrumbs">
              
  

  
    
    
  
    
            <div class="xleft">
        <span id="publishDate">Last Published: 2012-05-15</span>
                  &nbsp;| <span id="projectVersion">Version: 0.0.1-SNAPSHOT</span>
                      </div>
                <div class="xright">            <a href="http://code.google.com/p/jaks/" class="externalLink">Java Kick-Start</a>
            
  

  
    
    
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
        <div id="leftColumn">
          <div id="navcolumn">
               
  

  
    
    
  
    
                       <h5>Parent Project</h5>
            <ul>
              
    <li class="none">
                    <a href="../index.html">jaks</a>
          </li>
          </ul>
              <h5>Overview</h5>
            <ul>
              
    <li class="none">
              <strong>Introduction</strong>
        </li>
          </ul>
              <h5>Examples</h5>
            <ul>
              
    <li class="none">
                    <a href="example-subversion.html">Read Subversion Info</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
                          
                  
                  
                  
                  
                  
              
            <li class="expanded">
                    <a href="project-info.html">Project Information</a>
                  <ul>
                  
    <li class="none">
              <strong>About</strong>
        </li>
                  
    <li class="none">
                    <a href="dependencies.html">Dependencies</a>
          </li>
                  
    <li class="none">
                    <a href="source-repository.html">Source Repository</a>
          </li>
                  
    <li class="none">
                    <a href="license.html">Project License</a>
          </li>
                  
    <li class="none">
                    <a href="team-list.html">Project Team</a>
          </li>
                  
    <li class="none">
                    <a href="project-summary.html">Project Summary</a>
          </li>
              </ul>
        </li>
              
                
                    
                  
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
                                               <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img class="poweredBy"
                 alt="Built by Maven"
                 src="./images/logos/maven-feather.png"
                 width="90"
                 height="30"
                 border="1" />
          </a>
                           
  

  
    
    
  
    
            </div>
        </div>
        <div id="bodyColumn">
          <div id="contentBox">
            
	
		<div class="section"><h2>jaks-system<a name="jaks-system"></a></h2>
			<p>Why is it so difficult to launch a child process with Java? There's something like 
			half a dozen things you have to configure, and you have to set up service threads for
			stdout and stderr, and then you have to explicitly wait for it if you want to see if
			it worked. Honestly, whose use-case does this satisfy?</p>
			
			<p>Most times when I am multi-processing, I want to call out to a program, wait for it
			to complete, and get some data back. And I want the call to block, every time. If I want to run more 
			than one external process in parallel, I'll use a couple of threads.</p>
			
			<p>TODO...</p>
			
			<div class="source"><pre>$ cat /etc/hosts &gt; ~/copy-of-hosts.txt</pre></div>
			
			<p>And here is a version written in Java using classes from <tt>jaks</tt>.</p>
			<div class="source"><pre>final String CHARSET = StreamUtil.DEFAULT_CHARSET;
final File home = new File(System.getProperty(&quot;user.home&quot;)).getCanonicalFile();
final File copy = new File(home, &quot;copy-of-hosts.txt&quot;);

final String hosts = new Subprocess(&quot;cat&quot;, &quot;/etc/hosts&quot;).call(CHARSET);
StreamUtil.write(hosts, new FileOutputStream(copy), CHARSET);</pre></div>
            <p>Yeah, I know. The Java version is longer. But to us Java geeks, this is absolutely
            terse. I just ran <tt>cat</tt> in one simple line of code. In one more line, I copied the stdout
            from <tt>cat</tt> to a file.  And that code is easy to read. If I come back to this in six months,
            I will still know what this code does. Priceless. This is good enough for day-to-day scripting.</p>
		</div>
	

          </div>
        </div>
        <div class="clear">
          <hr/>
        </div>
        <div id="footer">
          <div class="xright">Copyright &#169;         
   
          2012.
    
      All Rights Reserved.    
  

  
    
    
  
    
  </div>
          <div class="clear">
            <hr/>
          </div>
        </div>
    </div>
  </body>
</html>
